﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;

namespace 学生成绩查询及选课系统.student
{
    public partial class myCourse : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
        public void bind()
        {
            string sql = "select s.stuname as '学生姓名',c.cname as '课程名',c.credit as '学分',cproperties as '课程性质',t.tname as '教师名' from student s" +
            " join grade g on s.stuno=g.stuno join course c on c.cno=g.cno" +
            " join teacher t on t.tno=c.tno where cstate=1 and  g.status=1 and s.stuno=" + Session["user"].ToString();
            DataTable dt = DBAccess.GetTable(sql);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

        protected void exportExcel_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename="+Session["user"].ToString()+".xls");
            HttpContext.Current.Response.Charset = "gb2312";
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            this.GridView1.AllowPaging = false;
            this.GridView1.RenderControl(htmlWrite);
            HttpContext.Current.Response.Write(stringWrite.ToString());
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
        public override void VerifyRenderingInServerForm(Control control) { }

    }
}